package lyo.levelup.swing.eventsclasswork;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class MainPanel extends JFrame
{
    public MainPanel()
    {
        ActionPanel action = new ActionPanel();
        add(action);
        setSize(200, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        TextField tf = new TextField();        
        setVisible(true);
    }
    class ActionPanel extends JPanel
    {
        private JLabel label;
        public ActionPanel()
        {
            setLayout(new BorderLayout());
            addText();
            addButtons();  
            addRadioButtons();
        }
        private void addText()
        {               
           // label = new JLabel("Text:");
            JTextField jf = new JTextField(10);
            add(jf, BorderLayout.NORTH);
        }
        private void addButtons()
        {
            JButton button = new JButton ("Commit");
            ActionChangeColor acc = new ActionChangeColor(label);
            button.addActionListener(acc);
            add(button,BorderLayout.SOUTH);
        }        
        private void addRadioButtons()
        {
            JPanel panel = new JPanel();
            Box b = Box.createVerticalBox();
            JRadioButton rb1 = new JRadioButton("RED");
            JRadioButton rb2 = new JRadioButton("GREEN");
            JRadioButton rb3 = new JRadioButton("BLUE");
            b.add(rb1);
            b.add(rb2);
            b.add(rb3);
            b.add(Box.createVerticalGlue());
            panel.add(rb1);
            panel.add(rb2);
            panel.add(rb3);
            add(b,BorderLayout.CENTER);
        }
        class ActionChangeColor implements ActionListener
        {
            private JLabel label;
            public ActionChangeColor(JLabel label)
            {
                this.label = label;
            }            
            @Override
            public void actionPerformed(ActionEvent ae)
            {
               JButton button = (JButton)ae.getSource();
               String label_ = button.getText();
               if(label_.equals("Commit"))
               {
                   label.setForeground(Color.red);
               }
            }            
        }
    }
    /*
    JOptionPane.showMessageDialog(null, "Mess", "Mess", ERROR, null);
Valera (11:11):
UIManager UI=new UIManager();
 UI.put("OptionPane.background", Color.white);
 UI.put("Panel.background", Color.white);
um.put("OptionPane.messageForeground", Color.red);
Valera (11:35):
JOptionPane.showMessageDialog(null, "Mess", "Mess", JOptionPane.ERROR_MESSAGE, null);
    */
    /*
    public class MainPanel extends JFrame
{
    public MainPanel()
    {
        ActionPanel action = new ActionPanel();
        add(action);
        setSize(200, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }
    class ActionPanel extends JPanel
    {
        private JLabel label;
        public ActionPanel()
        {
            setLayout(new BorderLayout());
            addText();
            addButtons();
            
        }
        private void addText()
        {
            label = new JLabel("text");
            add(label, BorderLayout.NORTH);
        }
        private void addButtons()
        {
            JButton button = new JButton ("Commit");
            ActionChangeColor acc = new ActionChangeColor(label);
            button.addActionListener(acc);
            add(button,BorderLayout.SOUTH);
        }
        private void addRatioButtons()
        {
                                
        }
        class ActionChangeColor implements ActionListener
        {
            private JLabel label;
            public ActionChangeColor(JLabel label)
            {
                this.label = label;
            }            
            @Override
            public void actionPerformed(ActionEvent ae)
            {
               JButton button = (JButton)ae.getSource();
               String label_ = button.getText();
               if(label_.equals("Commit"))
               {
                   label.setForeground(Color.red);
               }
            }            
        }
    }
    */
    
   /* public MainPanel()
    {
        setLayout(new BorderLayout());
        setSize(200,200);
        ButtonPanel bp = new ButtonPanel();        
        add(bp,BorderLayout.SOUTH);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }    

    class ButtonPanel extends JPanel
    {
        private JLabel label;
        private void addButton()
        {
            setLayout (new BorderLayout());
            JPanel buttonPanel = new JPanel();
            JButton ok = new JButton("RED");
            ok.addActionListener(new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent ae)
                {
                    label.setForeground(Color.red);
                }
            });
            buttonPanel.add(ok);            
        }
        private void addText()
        {
            setLayout(new BorderLayout());
            label = new JLabel("text");
            add(label, BorderLayout.CENTER);
        }
    }*/
}